package com.guanyong.webapi.ApplicationRunner;

import com.guanyong.model.VideoTypeModel;
import com.guanyong.services.VideoTypeService;
import com.guanyong.utils.Cache.ICahce.ICache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Administrator on 2017/10/11 0011.
 */

@Component
@Order(value=2)
public class TypeRunner implements CommandLineRunner {

    @Autowired
    ICache cache;

    @Value("${video.type.cache}")
    String videoTypeCache;

    @Autowired
    VideoTypeService videoTypeService;

    @Override
    public void run(String... args) throws Exception {
        List<VideoTypeModel> list = videoTypeService.getVideoTypeAll();
        for (VideoTypeModel videoTypeModel:list){
            cache.put(videoTypeCache,videoTypeModel.getId(),videoTypeModel.getName());
        }

        System.out.println("videoTypeCache初始化");
    }
}
